//
//  ForWardView.m
//  Weibo
//
//  Created by wpapple on 16/6/6.
//  Copyright © 2016年 wpapple. All rights reserved.
//

#import "ForWardView.h"

@interface ForWardView ()

@property (nonatomic,strong)IBOutlet UILabel *forWardLabel;

@property (nonatomic,strong)IBOutlet UIImageView *forWardImage;

@property (nonatomic,strong)IBOutlet NSLayoutConstraint *bottomHeight;

@property (nonatomic,strong)IBOutlet NSLayoutConstraint *forWardViewHeight;

@property (nonatomic,strong)IBOutlet NSLayoutConstraint *imageHeight;

@end

@implementation ForWardView

-(void)setStatus:(IWStatus *)status
{
    _status = status;
    
    IWStatus *forwardStatus = _status.retweeted_status;
    
    if (forwardStatus != nil) {
        
        self.imageHeight.constant = 90;
        self.bottomHeight.constant = 10;
        
        [self forwardStatus];
    }else
    {
        self.forWardViewHeight.constant = 0;
        self.imageHeight.constant = 0;
        self.bottomHeight.constant = 0;
        
        [self forWardViewHeight];
    }
    
}

-(void)forwardStatus
{
    IWStatus *forwardStatus = _status.retweeted_status;
    
    self.forWardLabel.text = [NSString stringWithFormat:@"@%@:%@",forwardStatus.user.name,forwardStatus.text];
    
    CGSize size = CGSizeMake(self.forWardLabel.width, CGFLOAT_MAX);
    
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
    
    [style setLineBreakMode:NSLineBreakByCharWrapping];
    
    NSDictionary *dict = @{NSFontAttributeName : self.forWardLabel.font,NSParagraphStyleAttributeName : style};
    
    CGRect rect = [self.forWardLabel.text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil];
    
    self.forWardViewHeight.constant = rect.size.height + 10;
    
    
    //设置数据
    if (_status.retweeted_status.pic_urls.count > 0 ) {
        NSDictionary *photo = _status.retweeted_status.pic_urls[0];
        
        NSURL *imageUrl = [NSURL URLWithString:photo[@"thumbnail_pic" ]];
        
        [self.forWardImage sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
        
    }else
    {
        self.imageHeight.constant = 0;
    }
}

@end
